<template>
<div>
  <div class="xinxi">
    <el-form ref="form" :model="form" label-width="80px" :inline="true">

      <el-form-item label="车辆类型">
        <el-radio-group v-model="form.vehicleType">
          <el-radio label="1">经济型</el-radio>
          <el-radio label="2">舒适型</el-radio>
          <el-radio label="3">豪华型</el-radio>
          <el-radio label="4">货运</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="能源消耗" style="margin-left: 100px">
        <el-radio-group v-model="form.energyType">
          <el-radio label="纯电">纯电</el-radio>
          <el-radio label="燃油">燃油</el-radio>
          <el-radio label="混合">混合</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-button type="primary" @click="findPage()" style="margin-left: 170px">查询</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
      <br><br>
      <el-form-item label="车型">
        <el-input v-model="form.vehicleModel" style="width: 180px" placeholder="请输入车型" clearable></el-input>
      </el-form-item>
      <el-form-item label="品牌" style="margin-left: 30px">
        <el-input v-model="form.brand" style="width: 200px" placeholder="请输入品牌" clearable></el-input>
      </el-form-item>
      <el-form-item label="厂家" style="margin-left: 30px">
        <el-input v-model="form.vender" style="width: 200px" placeholder="请输入厂家" clearable></el-input>
      </el-form-item>
      <el-button type="primary" @click="toAdd()"  style="margin-left: 100px">新增</el-button>
    </el-form>
  </div>
  <el-table
      :data="tableData"
      style="width: 100%">
    <el-table-column
        prop="id"
        label="序号">
    </el-table-column>
    <el-table-column
        prop="vehicleType"
        label="车辆类型">
      <template slot-scope="scope">
        {{ scope.row.vehicleType == 1 ? "经济型" : scope.row.vehicleType == 2 ? "舒适性" :
          scope.row.vehicleType == 3 ? "豪华型" :  "货运" }}
      </template>
    </el-table-column>
    <el-table-column
        prop="vehicleModel"
        label="车型">
    </el-table-column>
    <el-table-column
        prop="energyType"
        label="能源类型">
      <template slot-scope="scope">
        {{ scope.row.energyType == 1 ? "纯电" : scope.row.energyType == 2 ? "燃油" : "混合" }}
      </template>
    </el-table-column>
    <el-table-column
        prop="brand"
        label="品牌">
    </el-table-column>
    <el-table-column
        prop="vender"
        label="厂家">
    </el-table-column>
    <el-table-column
        prop="verifier"
        label="更新人">
    </el-table-column>
    <el-table-column
        prop="finallyTime"
        label="最后一次更新时间">
    </el-table-column>
    <el-table-column
        label="操作">
      <template slot-scope="scope">
        <el-row>
          <el-button type="text" size="small" @click="toUpdate(scope.row.id)" round>修改</el-button>
        </el-row>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[3, 10, 20, 30]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
  </el-pagination>
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="25%"
      >
    <el-form :model="ruleForm"  ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="车辆类型">
        <el-radio-group v-model="ruleForm.vehicleType">
          <el-radio :label="1">经济型</el-radio>
          <el-radio :label="2">舒适型</el-radio>
          <el-radio :label="3">豪华型</el-radio>
          <el-radio :label="4">货运</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="车型" prop="">
        <el-input v-model="ruleForm.vehicleModel" placeholder="请输入车型"></el-input>
      </el-form-item>
      <el-form-item label="能源消耗" >
        <el-radio-group v-model="ruleForm.energyType">
          <el-radio label="纯电">纯电</el-radio>
          <el-radio label="燃油">燃油</el-radio>
          <el-radio label="混合">混合</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="品牌" prop="">
        <el-input v-model="ruleForm.brand" placeholder="请输入品牌"></el-input>
      </el-form-item>
      <el-form-item label="厂家" prop="">
        <el-input v-model="ruleForm.vender" placeholder="请输入厂家"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">添加</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</div>
</template>
<script>
import axios from "axios";

export default {
  name: "VehicleType",
  data(){
    return{
      form:{},
      tableData: [],
      pageNum: 1,
      pageSize: 3,
      total: 0,
      ruleForm: {
        energyType: "",

      },
      dialogVisible: false,
    }
  },
  methods:{
    handleCurrentChange(val) {
      this.pageNum = val
      this.findPage();
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.findPage();
    },
    findPage() {
      axios.post(`http://localhost:9999/api-function/backstageCar/findPage?pageNum=${this.pageNum}&pageSize=${this.pageSize}`, this.form).then(res => {
        this.tableData = res.data.data.list
        this.total = res.data.data.total
      })
    },
    resetForm() {
      this.form = {}
      this.findPage();
    },
    toAdd(){
      this.ruleForm = {}
      this.dialogVisible = true;
    },
    submitForm() {
          axios.post(`http://localhost:9999/api-function/backstageCar/insertHuodong`,this.ruleForm).then(res => {
            if (res.data.code == 200) {
              this.$message.success("添加成功")
            } else {
              this.$message.error("添加失败")
            }
            this.dialogVisible = false;
            this.findPage();
          })
    },
    toUpdate(id){
      axios.post(`http://localhost:9999/api-function/backstageCar/toUpdate?id=${id}`).then(res => {
        this.ruleForm = res.data.data;
        this.dialogVisible = true;
      })
    }
  },
  created(){
    this.findPage()
  },
}
</script>



<style scoped>

</style>
